 $(function () {
                var token = localStorage.phone;
                $.ajax({
                    url:'https://newapp.icandrive.cn/api/score.php',
                    type:'post',
                    dataType:'json',
                    data:{token:token},
                    success:function(data){
                        if(data.status==200){
                            $('#score').text(data.score);
                            $(data.data).each(function () {
                                var leng=this.length;
                                if(leng==4){
                                    $('#listWrapper').append("<li class='list-group-item'>"+
                                                             "<div class='prize'>"+
                                                             "<div class='prize-info prize-info1' id='"+this[0].id+"'>"+
                                                             "<img src='https://newapp.icandrive.cn/tp/Uploads/"+this[0].goods_pic+"' >"+
                                                             "<h4>"+this[0].goods_name+"<i>"+this[0].goods_score+"</i></h4>"+
                                                           /*  "<hr/>"+*/
                                                             "<p>"+this[0].goods_intro+"</p>"+
                                                             "</div>"+
                                                             "<div class='prize-info prize-info2'  id='"+this[1].id+"'>"+
                                                             "<img src='https://newapp.icandrive.cn/tp/Uploads/"+this[1].goods_pic+"'>"+
                                                             "<h4>"+this[1].goods_name+"<i>"+this[1].goods_score+"</i></h4>"+
                                                             "<hr/>"+
                                                             "<p>"+this[1].goods_intro+"</p>"+
                                                             "</div>"+
                                                             "</div>"+
                                                             "<div class='prize'>"+
                                                             "<div class='prize-info prize-info2'  id='"+this[2].id+"'>"+
                                                             "<img src='https://newapp.icandrive.cn/tp/Uploads/"+this[2].goods_pic+"'>"+
                                                             "<h4>"+this[2].goods_name+"<i>"+this[2].goods_score+"</i></h4>"+
                                                             "<hr/>"+
                                                             "<p>"+this[2].goods_intro+"</p>"+
                                                             "</div>"+
                                                             "<div class='prize-info prize-info1'  id='"+this[3].id+"'>"+
                                                             "<img src='https://newapp.icandrive.cn/tp/Uploads/"+this[3].goods_pic+"'>"+
                                                             "<h4>"+this[3].goods_name+"<i>"+this[3].goods_score+"</i></h4>"+
                                                             "<hr/>"+
                                                             "<p>"+this[3].goods_intro+"</p>"+
                                                             "</div>"+
                                                             "</div>"+
                                                             "</li>")
                                }else if(leng==3){
                                    $('#listWrapper').append("<li class='list-group-item'>"+
                                                             "<div class='prize'>"+
                                                             "<div class='prize-info prize-info1' id='"+this[0].id+"'>"+
                                                             "<img src='https://newapp.icandrive.cn/tp/Uploads/"+this[0].goods_pic+"' >"+
                                                             "<h4>"+this[0].goods_name+"<i>"+this[0].goods_score+"</i></h4>"+
                                                             "<hr/>"+
                                                             "<p>"+this[0].goods_intro+"</p>"+
                                                             "</div>"+
                                                             "<div class='prize-info prize-info2'  id='"+this[1].id+"'>"+
                                                             "<img src='https://newapp.icandrive.cn/tp/Uploads/"+this[1].goods_pic+"'>"+
                                                             "<h4>"+this[1].goods_name+"<i>"+this[1].goods_score+"</i></h4>"+
                                                             "<hr/>"+
                                                             "<p>"+this[1].goods_intro+"</p>"+
                                                             "</div>"+
                                                             "</div>"+
                                                             "<div class='prize'>"+
                                                             "<div class='prize-info prize-info2'  id='"+this[2].id+"'>"+
                                                             "<img src='https://newapp.icandrive.cn/tp/Uploads/"+this[2].goods_pic+"'>"+
                                                             "<h4>"+this[2].goods_name+"<i>"+this[2].goods_score+"</i></h4>"+
                                                             "<hr/>"+
                                                             "<p>"+this[2].goods_intro+"</p>"+
                                                             "</div>"+
                                                             "</li>")
                                }else if(leng==2){
                                    $('#listWrapper').append("<li class='list-group-item'>"+
                                                             "<div class='prize'>"+
                                                             "<div class='prize-info prize-info1' id='"+this[0].id+"'>"+
                                                             "<img src='https://newapp.icandrive.cn/tp/Uploads/"+this[0].goods_pic+"' >"+
                                                             "<h4>"+this[0].goods_name+"<i>"+this[0].goods_score+"</i></h4>"+
                                                             /*"<hr/>"+*/
                                                             "<p>"+this[0].goods_intro+"</p>"+
                                                             "</div>"+
                                                             "</div>"+
                                                             "<div class='prize'>"+
                                                             "<div class='prize-info prize-info2' id='"+this[1].id+"'>"+
                                                             "<img src='https://newapp.icandrive.cn/tp/Uploads/"+this[1].goods_pic+"'>"+
                                                             "<h4>"+this[1].goods_name+"<i>"+this[1].goods_score+"</i></h4>"+
                                                             "<hr/>"+
                                                             "<p>"+this[1].goods_intro+"</p>"+
                                                             "</div>"+
                                                             "</li>")
                                }else{
                                    $('#listWrapper').append("<li class='list-group-item'>"+
                                                             "<div class='prize'>"+
                                                             "<div class='prize-info prize-info1'  id='"+this[0].id+"'>"+
                                                             "<img src='https://newapp.icandrive.cn/tp/Uploads/"+this[0].goods_pic+"' >"+
                                                             "<h4>"+this[0].goods_name+"<i>"+this[0].goods_score+"</i></h4>"+
                                                             "<hr/>"+
                                                             /*"<p>"+this[0].goods_intro+"</p>"+*/
                                                             "</div>"+
                                                             "</li>")
                                }
                                $(".prize-info").click(function(){
                                    var score=parseInt($(this).find('i').text());
                                    var myScore=parseInt($('#score').text());
                                    if(myScore-score<0){
                                        layer.msg('积分不足')
                                    }else{
                                        $(".detail_popup").removeClass("hidden")
                                        $(".detail_popup").addClass("show")
                                        var id =$(this).attr('id');
                                        var goods_name =$(this).find('h4').html().split("<")[0];
                                        var img=$(this).find('img').prop('src');
                                        $('#a_goods_name').html(goods_name);
                                        $('#a_goods_img').prop('src',img);
                                        $('#a_goods_score').html(score);
                                        $('#a_score').html(myScore-score);
                                        $('#id').val(id);
                                    }
                                })


                            });
                        }
                    },
                    error:function(){
                        layer.msg('系统繁忙',function(){
                            history.go(0)
                        },1000);
                    }

                });
            });
            function buy(){
                var need_score = $('#a_goods_score').html();
                var goods_id = $('#id').val();
                var get_intergral_adressinput = $(".get_intergral_adressinput").val();
                console.log(get_intergral_adressinput );
                var token = localStorage.phone;
                $.ajax({
                    url:'https://newapp.icandrive.cn/api/buy_goods.php',
                    type:'post',
                    dataType:'json',
                    data:{token:token,need_score:need_score,goods_id:goods_id,number:1,user_address:get_intergral_adressinput},
                    success:function(data){
                        if(data.status==200){
                            $('#score').text($('#a_score').html());
                            layer.msg('购买成功');
                            $(".detail_popup").removeClass("show")
                            $(".detail_popup").addClass("hidden")
                        }else{
                            layer.msg('购买失败');
                        }
                    }
                })
            }
